package com.woniuxy.three.pms.util;

import java.io.IOException;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
/**
 * 
*@ProjectName:Pms
*@Date:2019年6月18日
*@ClassName:WebSocketUtil.java
*@Author:ThinkPad
*@Description:TODO (用一句话描述该文件做什么)
*@Version:版本
*@See：参考版本
*
 */
public class WebSocketUtil {
		public static Map<String, Session> ONLINE_USER= new ConcurrentHashMap<String, Session>();
	
		
		public static void sendmessage(Session session,String message) {
			if(session==null) {
				return;
			}
			final RemoteEndpoint.Basic basic= session.getBasicRemote();
			if(basic==null) {
				return;
			}
			try {
				basic.sendText(message);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.println("消息发送失败");
				e.printStackTrace();
			}
			
		}
		
		public static void sendall(String message) {
						
			ONLINE_USER.forEach((sessionId, session) -> sendmessage(session, message));
		}
}
